package com.icecloud.cloud.upms.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.icecloud.cloud.upms.dao.RoleDao;
import com.icecloud.cloud.upms.entity.Role;
import com.icecloud.cloud.upms.entity.base.BaseDepartment;

/**
* @author penghaozhong 
* E-mail:penghaozhong@163.com
* @version 2016年8月7日 下午10:26:42
* 
*/
@Service
@Transactional(readOnly=true)
public class RoleService {
	
	@Autowired
	private RoleDao roleDao;
	
	/**
	 * 保存角色
	 * @param role
	 * @return
	 */
	@Transactional(readOnly=false)
	public int save(Role role)throws DataAccessException{
		return roleDao.insert(role);
	}
	
	/**
	 * 角色列表
	 * @param roleName
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public List<Role> list(String roleName,int pageNum, int pageSize){
		Role entity = new Role();
		if(StringUtils.isNotBlank(roleName)){
			entity.setRoleName(roleName);
		}
		PageHelper.startPage(pageNum, pageSize);
		return roleDao.list(entity);
	}

}
